public class Polindrom {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println("Polindrom");
		int[] chisla = new int[] { 123123, 222600, -1, 3, 55436182 };
		for (int i = 0; i < chisla.length; i++) {
			int chislo = chisla[i];
			System.out.println(chislo + "=" + isPolindrom(chislo));
		}
		
		int[] mas = new int []{5,5,3,2,1,5,5,5,8,9,5,0};
		for (int i = 0; i < mas.length; i++) {
			System.out.print(mas[i] + " ");
		}
		System.out.println("");
		System.out.println(podschetChisla(mas,5));
		
		System.out.println("");
		System.out.println(sortVyborom(mas));
		
	}

	// /////////////////////////////////////////////////////////////////////////////////

	public static boolean isPolindrom(int value) {

		if (value <= 0) {
			return false;
		}

		if (String.valueOf(value).length() % 2 != 0) {
			return false;
		}

		String valueString = String.valueOf(value);
		int length = String.valueOf(value).length();
		int ser = length / 2;

		String strHalf0 = valueString.substring(0, ser);
		String strHalf1 = valueString.substring(ser, length);

		int intHalf0 = Integer.valueOf(strHalf0);
		int intHalf1 = Integer.valueOf(strHalf1);

		int sum1 = sumElements(intHalf0);
		int sum2 = sumElements(intHalf1);
		return sum1 == sum2;
	}

	public static int sumElements(int value) {

		int length = String.valueOf(value).length();
		int sum = 0;
		for (int i = 0; i < length; i++) {
			sum += defineElem(value, i);
		}
		return sum;
	}

	public static int defineElem(int value, int index) {

		int elementAsSring = String.valueOf(value).charAt(index);
		return Integer.valueOf(elementAsSring).intValue();
	}
	///////////////////////////////////////////////////////////////////////////////////////////

	
	public static int podschetChisla(int []mas,int chislo) {
		
		int sum = 0;
		
		if (mas == null) {
			System.out.println("massiv pust");
		}
		
		for (int i = 0; i < mas.length; i++){
			
			 if(mas[i]== chislo){
			 sum += 1;
			 }
		}	
		return sum;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public static int findMinValueIndex(int [] mas,int starIndex){
		int index = starIndex;
		int value = mas[starIndex];
		for (int i = starIndex+1; i < mas.length; i++) {
			if (mas[i]< value){
				value = mas[i];
				index = i;
			}
			
		}
		return index;
	}
	
	
	
	
	public static int [] obmen(int[]mas,int ind0,int ind1){
		int val0 = mas[ind0];
		int val1 = mas[ind1];
		mas[ind0] = val1;
		mas[ind1] = val0;
		
		return mas;
	}
	
	
	
	
	
	public static int [] sortVyborom(int []mas) {
		
		if (mas == null) {
			System.out.println("massiv pust");
		}
		
		for (int i = 0; i < mas.length-1; i++) {
			int min = findMinValueIndex(mas,i);
			mas = obmen(mas,i,min);
				
			}
			
		return mas;
		
		
	}
	
}











